<extend name="Layout:layout_edit" />
<block name="body_content_block">
    <form action="{:AddonU('Task/generate_number_save')}" method="post" id="frmMain">
        <input type="radio" name="noType" checked="checked" value='mob'>手机号码
        <input type="radio" name="noType" value='tel'>固话号码                            
        <table>
            <tr><th>省份：</th><td><select id="province" name="province" title="请选择省份" data-url="{:AddonU('Task/get_province_json')}"></select></td></tr>
            <tr><th>城市：</th><td><select id="city" name="city" title="请选择城市" data-url="{:AddonU('Task/get_city_json')}"></select></td></tr>
            <tr>
                <th>运营商：</th><td>
                    <select id="operator" name="operator" title="请选择运营商">
                        <option value="">请选择运营商</option>
                        <option value="1">移动</option>
                        <option value="2">联通</option>
                        <option value="3">电信</option>
                    </select>
                </td></tr>
            <tr>
                <th>归属地号段：</th><td>
                    <select id="areaName" name="areaName" title="请选择归属地号段" data-url="{:AddonU('Task/get_startNo_list')}"></select>
                </td></tr>
            <tr>
                <th>号码前缀：</th><td>
                    <input type="text" name="prefix" placeholder="请输入号码前缀" value="{$data.prefix}" title="请填写号码前缀!"/>
                </td></tr>
            <tr>
                <th>开始号码：</th><td>
                    <input type="text" name="startNo" placeholder="请输入开始号码" title="请输入开始号码(固话不限位数,手机限制11位)!" size="16"/><span id="startNoTip"></span>
                    号码数量 <input type="text" name="endNo" placeholder="结束号码" title="请填写结束号码!" size="8" value="10000"/>
                </td></tr>
            <tr>
                <th>尾数选号：</th><td>
                    <input type="checkbox" name="chkLastNo" id="chkLastNo" value="1"/>
                    <span style="display:none;">
                        尾数号 <input type="text" name="lastNo" placeholder="尾数号" title="请输入尾数号!" size="6"/>
                        最大数量 <select name="maxNum">
                            <option value="" selected="selected">默认</option>
                            <option value="1">1</option>
                            <option value="10">10</option>
                            <option value="100">100</option>
                            <option value="1000">1000</option>
                            <option value="10000">10000</option>
                        </select>
                    </span>
                </td></tr>
            <tr>
                <th>任务拆分</th><td>
                    <input type="checkbox" name="chkTaskSplit" id="chkTaskSplit" value="1"/>
                    <span style="display:none;">
                        任务号码数：<input type="text" name="telsCount" size="4"/> 任务数：<input type="text" name="taskCount" size="4"/>
                    </span>
                </td></tr>
            <tr>
                <th>去除重复</th><td>
                    <input type="checkbox" name="skipDuplicate" value="1"/>
                </td></tr>
            <tr>
                <th>生成规则：</th><td>
                    <input type="radio" name="rule" value="order"/>顺序生成 <input type="radio" name="rule" value="random" checked="checked"/>乱序生成
                </td></tr>
        </table>
        <input type="hidden" name="name"/>
        <input type="hidden" name="taskStrategyID" value="{$tsid}"/>
    </form>
</block>
<block name="body_after_block">
    <script>
        item_form.resize_owner_dialog({width:400});
        $('input[name="noType"]').click(function () {
            setModeUI($(this).val());
        })
        function setModeUI(val) {
            if (val == 'tel') {
                $('[name="province"]').parentsUntil('tr').parent().addClass('tohide').hide();
                $('[name="city"]').parentsUntil('tr').parent().addClass('tohide').hide();
                $('[name="operator"]').parentsUntil('tr').parent().addClass('tohide').hide();
                $('[name="areaName"]').parentsUntil('tr').parent().addClass('tohide').hide();
            } else {
                $('[name="province"]').parentsUntil('tr').parent().removeClass('tohide').toggle('show');
                $('[name="city"]').parentsUntil('tr').parent().removeClass('tohide').toggle('show');
                $('[name="operator"]').parentsUntil('tr').parent().removeClass('tohide').toggle('show');
                $('[name="areaName"]').parentsUntil('tr').parent().removeClass('tohide').toggle('show');
            }
        }

        function submitform(rule) {
            $('#frmMain input:button').button({'disabled': true, 'label': '正在处理...'});
            $('input[name="rule"]').val(rule);
            $.get('{:AddonU("Task/check_history","startNo=varkey&tsid=".$tsid)}'.replace('varkey', $('input[name="startNo"]').val()), function (data) {
                if (data.count > 0) {
                    if (!confirm(data.msg)) {
                        return;
                    }
                }
                $('#frmMain').submit();
            })
        }
        item_form.combobox('#province', {onSelect: function (val) {
                item_form.combobox('#city', {queryParams: {province: val.id}, onSelect: function () {
                        select_start_no();
                    }});
            }});
        item_form.combobox('#operator', {onSelect: function (val) {
                $('input[name="operator"]').data('text', val.text);
                select_start_no();
            }});
        
        function select_start_no() {
            var province = $('[name="province"]').val();
            var city = $('[name="city"]').val();
            var isp = $('[name="operator"]').val();
            isp = $('input[name="operator"]').data('text');
            if (!province || !city || !isp) {
                return;
            }
            var areaName = province + city;
            if (province == '北京' || province == '上海' || province == '天津' || province == '重庆') {
                areaName = city;
            }
            item_form.combobox('#areaName', {queryParams: {areaname: areaName, isp: isp}, onSelect: function (val) {
                    $('input[name="startNo"]').val(val.id + '0000');
                    $('input[name="endNo"]').val('10000');
                    var area = val.text;
                    $('input[name="name"]').val(area);
                    area = area.substring(0, area.indexOf(' '));
                    $('[name="areaName"]').data('text',area);
                }})
        }
        $('input[name="startNo"]').blur(function () {
            var val = $(this).val();
            var len = val.length;
            setname();
            $('#startNoTip').text('(' + len + '位)');
        })
        $('input[name="prefix"]').blur(function () {
            setname();
        })
        function setname() {
            var val = $('input[name="startNo"]').val();
            val = $('input[name="prefix"]').val() + val;
            var area=$('[name="areaName"]').data('text');
            val = area + ' >> ' + val;
            $('input[name="name"]').val(val);
        }
        $('#chkLastNo').change(function () {
            var $this = $(this);
            if ($this.prop('checked')) {
                $this.next().show();
                $('#chkTaskSplit').parent().parent().hide();
            } else {
                $this.next().hide();
                $('#chkTaskSplit').parent().parent().show();
            }
        })
        $('#chkTaskSplit').change(function () {
            var $this = $(this);
            if ($this.prop('checked')) {
                $this.next().show();
                $('#chkLastNo').parent().parent().hide();
            } else {
                $this.next().hide();
                $('#chkLastNo').parent().parent().show();
            }
        })
        $('input[name="lastNo"]').blur(function () {
            var data = [1, 10, 100, 1000, 10000];
            var n = data.length - $(this).val().length - 1;
            var str = '<option value="">默认</option>';
            for (var i = n; i < data.length; i++) {
                str += '<option value="' + data[i] + '"' + (i == n ? ' selected="selected"' : '') + '>' + data[i] + '</option>';
            }
            $('select[name="maxNum"]').html(str);
        })
        $('input[name="telsCount"]').blur(function () {
            var $this = $(this);
            if ($this.val() && ($this.val() < 1 || $this.val() > 1000)) {
                $.messager.alert('提示', '号码数范围0-1000');
                $this.val('1000');
            }
        })
        $('input[name="taskCount"]').blur(function () {
            var $this = $(this);
            if ($this.val() && ($this.val() < 1 || $this.val() > 10)) {
                $.messager.alert('提示', '任务数范围0-10');
                $this.val('10');
            }
        })
    </script>
</block>